<template>
    <div>
        <avue-form ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">

        </avue-form>
    </div>
</template>

<script>
import {uploadPath} from "@/config/env";

export default {
    data() {
        return {
            obj: {},
            treeData: [],
            initSuccess: false,
            defaultData: {
                pid: null,
                name: null,
                twoUrl: null,
                url: null,
                icon: "el-Document",
                sort: 0,
                root: 3,
                disable: 0,
            },
        }
    },
    props: {
        uri: {},
        rowData: {},
    },
    computed: {
        option() {
            return {
                // size: "small",
                submitBtn: true,
                emptyBtn: true,
                submitText: '提交',
                emptyText: "关闭",
                column: [
                    {
                        label: '父级',
                        prop: 'pid',
                        type: 'tree',
                        labelWidth: 110,
                        span: 20,
                        display: true,
                        dicData: this.treeData,
                        props: {
                            value: "id",
                            label: "name",
                            children: "menus"
                        },
                        rules: [{
                            required: true,
                            message: "请选择 指定父id",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '目录级别',
                        prop: 'root',
                        type: 'radio',
                        labelWidth: 110,
                        dicData: this.dict.get('MENU_ROOT'),
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请选择 目录级别",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '菜单名',
                        prop: 'name',
                        labelWidth: 110,
                        maxlength: 32,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 菜单名",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '路由',
                        prop: 'url',
                        labelWidth: 110,
                        maxlength: 128,
                        showWordLimit: true,
                        span: 20,
                        display: this.obj.root === 3,
                        rules: [{
                            required: false,
                            message: "请输入 菜单url",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '第二路由',
                        prop: 'twoUrl',
                        labelWidth: 110,
                        maxlength: 128,
                        showWordLimit: true,
                        display: this.obj.root === 3,
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请输入 第二路由url, 前后端分离前端使用第二路由",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '图标',
                        prop: 'icon',
                        type: 'icon',
                        labelWidth: 110,
                        iconList: this.defaultdata.iconList,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请选择 图标",
                            trigger: "blur"
                        }],
                    },
                    {
                        label: '排序',
                        prop: 'sort',
                        type: 'number',
                        labelWidth: 110,
                        precision: 0,  //保留小数位,
                        min: 0,
                        max: 99999999999,
                        step: 1,
                        row: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 排序",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '禁用',
                        prop: 'disable',
                        type: 'switch',
                        labelWidth: 110,
                        display: this.obj.root === 3,
                        dicData: this.dict.get('WHETHER',false),
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请选择 禁用",
                            trigger: "blur"
                        }]
                    },

                ]
            }
        }
    },
    created() {
        this.obj = this.defaultData;
        this.obj.pid = this.rowData.pid;
        this.treeData = JSON.parse(JSON.stringify(this.rowData.pidDic));
        this.initSuccess = true;
    },
    methods: {
        emptytChange() {
            this.$emit('closeDialog', false);
        },
        submit(form, done) {
            this.crud.post(this.uri.info, this.obj).then((res) => {
                console.debug(res);
                if (res.data.code == 200) {
                    this.$emit('closeDialog', true, res.data.data);
                }
                done(form);
            }).catch((err) => {
                console.error(err);
                done(form);
            })
        },
    }
}
</script>